package com.dk.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dk.data.Result;
import com.dk.data.ResultEnum;
import com.dk.pojo.content.TbContentCategory;
import com.dk.service.content.ContenCategoryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("contentCate")
public class ContentCategoryController {

    private final Logger logger = LoggerFactory.getLogger(ContentCategoryController.class);

    @Reference
    private ContenCategoryService contenCategoryService;

    @RequestMapping("listContentCate")
    @ResponseBody
    public Result listContentCate() {
        try {
            List<TbContentCategory> list = contenCategoryService.listContentCate();
            return Result.response(ResultEnum.OK).setData(list);
        } catch (Exception e) {
            logger.error("获取广告分类列表",e);
            return Result.response(ResultEnum.FAIL);
        }
    }

    @RequestMapping("saveCate")
    @ResponseBody
    public Result saveCate(TbContentCategory category) {
        try {
            int i = contenCategoryService.saveCate(category);
            return Result.response(ResultEnum.OK);
        } catch (Exception e) {
            logger.error("保存广告分类错误",e);
            return Result.response(ResultEnum.FAIL);
        }
    }

    @RequestMapping("cateById")
    @ResponseBody
    public Result cateById(Long id) {
        try {
            TbContentCategory category = contenCategoryService.cateById(id);
            return Result.response(ResultEnum.OK).setData(category);
        } catch (Exception e) {
            logger.error("获取广告分类错误",e);
            return Result.response(ResultEnum.FAIL);
        }
    }

    @RequestMapping("updateCate")
    @ResponseBody
    public Result updateCate(TbContentCategory category) {
        try {
            int i = contenCategoryService.updateCate(category);
            return Result.response(ResultEnum.OK);
        } catch (Exception e) {
            logger.error("广告分类修改错误",e);
            return Result.response(ResultEnum.FAIL);
        }
    }
}
